package jvm;

import org.openjdk.jol.info.ClassLayout;

public class JOLSample {

    public static void main(String[] args) {
        /*Object 占用16字节*/
        ClassLayout classLayout = ClassLayout.parseInstance(new Object());
        System.out.println(classLayout.toPrintable());

        /*数组*/
        int[] ints = new int[]{};
        ClassLayout classLayoutArr = ClassLayout.parseInstance(ints);
        System.out.println(classLayoutArr.toPrintable());

        /*创建A对象占用多少字节--8+4+4+4+1+4*/
        ClassLayout classLayoutA = ClassLayout.parseInstance(new A());
        System.out.println(classLayoutA.toPrintable());
    }


    public static class A{
                //8B mark word
                //4B klass pointer 如果关闭占用8B
        int id; //4B
        String name; //关闭指针压缩 占用8B
        byte b; //1B -内部对齐+3B
        Object o; //关闭指针压缩 则占用8B
    }

}
